/**
 * 功能描述
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper")
	var store =require("store");
	var activeUser = store.get("user");
	
    module.exports = {
    	setData:function(widget,date){
    		 var datas;
    		 var params = [{days:"周一"+"("+date.weekday(1).format("MM.DD")+")",day:date.weekday(1).format("x"),count:1},
             	{days:"周二"+"("+date.weekday(2).format("MM.DD")+")",day:date.weekday(2).format("x"),count:2},
             	{days:"周三"+"("+date.weekday(3).format("MM.DD")+")",day:date.weekday(3).format("x"),count:3},
             	{days:"周四"+"("+date.weekday(4).format("MM.DD")+")",day:date.weekday(4).format("x"),count:4},
             	{days:"周五"+"("+date.weekday(5).format("MM.DD")+")",day:date.weekday(5).format("x"),count:5},
             	{days:"周六"+"("+date.weekday(6).format("MM.DD")+")",day:date.weekday(6).format("x"),count:6},
             	{days:"周日"+"("+date.weekday(7).format("MM.DD")+")",day:date.format("x"),count:7},
             ];
    		date = date.weekday(-6);
    		//alert(date.format("MM.DD"));
    		aw.ajax({
				url: "api/cate/dishmenu/queryoneweek",
				data: {
					"servicePoint":activeUser.servicePoint.pkServicePoint,
					"menuDate":date.startOf("day").format("x"),
					
					fetchProperties: "pkDishMenu,dishes,menuDate,dishMenuType,dishes.pkDish,dishes.name" ,
				},
				dataType: "json",
				success: function(data){
					widget.get("model").datas = data;
					widget.renderPartial(".J-table");
				}
			})
			widget.get("model").dates = params;
        	widget.renderPartial(".J-table");
    		var subnav=widget.get("subnav");
    		
    	},copyToNextWeek:function(widget,date){
    		var monday = date.weekday(1);
    		aw.ajax({
    			url:"api/cate/dishmenu/copytonextweek",
    			data:{
    				"servicePoint":activeUser.servicePoint.pkServicePoint,
    				"menuDate":date.startOf("day").format("x"),
    			},
    			dataType: "json",
				success: function(data){
					widget.get("model").datas = data;
					//widget.renderPartial(".J-table");
				}
    		})
        	widget.renderPartial(".J-table");
    		var subnav=widget.get("subnav");
    	}
    };
});
